<div class="line-label">
  <%= page_entries_info(@materials_wish_lists) %>
</div>

<% if @materials_wish_lists.size > 0 %>
  <% show_all_wish_list = session[:wish_list_selected].nil? ||  session[:wish_list_selected] == "-1" %>
  <% wish_list_has_count_attribute = !show_all_wish_list && WishList.has_count_attribute?(session[:wish_list_selected].to_i) %>
  <% wish_list_is_cart = !show_all_wish_list && WishList.is_cart?(session[:wish_list_selected].to_i) %>
  <% wish_list_is_reserve = !show_all_wish_list && WishList.is_reserve?(session[:wish_list_selected].to_i) %>
  <% show_up_down_action = !show_all_wish_list && !wish_list_is_cart && !wish_list_is_reserve %>

  <% form_tag my_wish_list_define_materials_to_special_list_path, :id => 'my_form' do %>
    <div>
      <table style="border: none">
        <tr>
          <td>
            <a href="" onClick="$$('#my_form input.check').each(function(box){box.checked=true});return false;"/><%=t('lbl_select_all')%></a> |
            <a href="" onClick="$$('#my_form input.check').each(function(box){box.checked=false});return false;"/><%=t('lbl_deselect_all')%></a>
          </td>
          <td align="right"><%= will_paginate(@materials_wish_lists, options_will_paginate({:params => {:controller => :my_wish_lists, :action => :paginate_wish_list_materials}})) %></td>
        </tr>
        <tr>
          <td colspan="3">
            <table>
              <thead>
                <tr>
                  <th colspan="2"></th>
                  <% if show_all_wish_list %>
                    <th><%=t('activerecord.models.wish_list')%></th>
                  <% end %>
                  <th><%=t('activerecord.models.material')%></th>

                  <% if wish_list_is_cart || wish_list_is_reserve %>
                    <th> <%= t('activerecord.attributes.material.price') %> </th>
                  <% end %>

                  <% if wish_list_has_count_attribute %>
                    <th> <%= t('activerecord.attributes.materials_wish_list.count') %> </th>
                  <% end %>

                  <th colspan="4"><%= t('title_actions') %></th>
                </tr>
              </thead>

              <tbody>
                <% actual_row = 0 %>
                <% @materials_wish_lists.each do |material_wish_list| %>
                  <% actual_row += 1 %>
                  <tr>
                    <td><%= check_box_tag 'material_wish_lists_selected[]', material_wish_list.id, false, :class => "check" %></td>
                    <td><%="#{@materials_wish_lists.offset + actual_row}."%></td>
                    <% if show_all_wish_list %>
                      <td><%=  material_wish_list.wish_list.name %></td>
                    <% end %>

                    <% @material = material_wish_list.material %>
                    <td>
                      <%= render :partial => 'materials/material_info_for_list', :object => @material %>
                    </td>

                    <% if wish_list_is_cart || wish_list_is_reserve %>
                      <td> <%="#{@material.currency.symbol} #{@material.price}" %> </td>
                    <% end %>

                    <% if wish_list_has_count_attribute %>
                    <td align="right"> <%= material_wish_list.count || "0" %> </td>
                    <% end %>

                    <% if !show_up_down_action || actual_row == 1 && @materials_wish_lists.offset == 0 %>
                      <td></td>
                    <% else %>
                      <td class="action"><%= link_to_remote t('btn_up'), :url => my_wish_list_up_material_path(material_wish_list), :update => "wish_list_materials"%></td>
                    <% end %>
                    <% if !show_up_down_action || (@materials_wish_lists.offset + actual_row) == @materials_wish_lists.total_entries %>
                      <td></td>
                    <% else %>
                      <td class="action"><%= link_to_remote t('btn_down'), :url => my_wish_list_down_material_path(material_wish_list), :update => "wish_list_materials"%></td>
                    <% end %>

                    <% if wish_list_is_cart || wish_list_is_reserve %>
                      <td></td>
                    <% else %>
                      <td class="action"><%= link_to t('btn_show'), my_wish_list_show_material_path(material_wish_list.id) %></td>
                    <% end %>

                    <% if wish_list_has_count_attribute %>
                      <td class="action"><%= link_to t('.btn_edit_material_wish_list'), my_wish_list_edit_material_path(material_wish_list)%></td>
                    <% else %>
                      <td></td>
                    <% end %>

                    <!--td class="action"><%#= link_to_remote t('.btn_delete_material'), :url => my_wish_list_delete_material_path(material_wish_list), :confirm => t('msg_sure_destroy?'), :update => "wish_list_materials" %></td-->
                  </tr>
                <% end %>
              </tbody>
            </table>
          </td>
        </tr>
      </table>
      <div>
          <% if flash[:notice].is_a?(Array) %>
            <p style="color: green"><%= flash[:notice].join('<br/>') %></p>
          <% else %>
            <p style="color: green"><%= flash[:notice] %></p>
          <% end %>
          <% if flash[:error].is_a?(Array) %>
            <p style="color: red"><%= flash[:error].join('<br/>') %></p>
          <% else %>
            <p style="color: red"><%= flash[:error] %></p>
          <% end %>
          <% if flash[:alert].is_a?(Array) %>
            <p style="color: red"><%= flash[:alert].join('<br/>') %></p>
          <% else %>
            <p style="color: red"><%= flash[:alert] %></p>
          <% end %>

          <% flash[:notice] = nil %>
          <% flash[:error] = nil %>
          <% flash[:alert] = nil %>
      </div>
    </div>
    <div>
      <%= submit_to_remote( "delete_materials", t('.btn_delete_materials'), :url => { :action => :delete_materials }, :update => "wish_list_materials", :confirm => t('.msg_delete_materials?')) %>
      <% if wish_list_is_cart %>
        <%= submit_to_remote( "process_cart", t('.btn_process_cart'), :url => { :action => :process_cart }, :update => "wish_list_materials", :confirm => t('.msg_process_cart?')) %>
      <% end %>

      <% if wish_list_is_reserve %>
        <%= submit_to_remote( "process_reserve", t('.btn_process_reserve'), :url => { :action => :process_reserve }, :update => "wish_list_materials", :confirm => t('.msg_process_reserve?')) %>
      <% end %>

      <% if !wish_list_is_cart && !wish_list_is_reserve %>
        <%= submit_tag t('.btn_add_to_cart'), :name => "define_materials_to_cart", :confirm => t('.msg_add_to_cart?') %>
        <%#= submit_tag t('.btn_add_to_reserve'), :name => "define_materials_to_reserve", :confirm => t('.msg_add_to_reserve?') %>
      <% end %>

      <% if !session[:special_return_to_controller].nil? %>
        <br/>
        <br/>
        <%=link_to t('btn_back'), :controller => session[:special_return_to_controller], :action => :special_return_to%>
      <% end %>

    </div>
  <% end %>
<% end %>
